//
//  WSForumTableViewCell.m
//  RunningMan
//
//  Created by 王帅 on 16/5/19.
//  Copyright © 2016年 WSJ. All rights reserved.
//

#import "WSForumTableViewCell.h"
#import "WSMyTool.h"

@interface WSForumTableViewCell ()
@property (nonatomic, strong) UILabel *lableTitle;
@property (nonatomic, strong) UILabel *lableUserName;
@property (nonatomic, strong) UILabel *lableTime;
@property (nonatomic, strong) UILabel *lableCom;
@property (nonatomic, strong) UILabel *lableP;
@property (nonatomic, strong) UIImageView *imageViewUserPhoto;
@end

@implementation WSForumTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubView];
    }
    
    return self;
}
- (void)setModelContent:(WSForumModel *)modelContent{
    _modelContent = modelContent;
    self.lableTitle.text = modelContent.title;
}
- (void)setModelComPra:(WSForumModel *)modelComPra{
    _modelContent = modelComPra;
    self.lableCom.text = [NSString stringWithFormat:@"评论: %@", modelComPra.commentCount];
    self.lableP.text = [NSString stringWithFormat:@"赞: %@", modelComPra.praiseCount];
    
}

- (void)setModelUse:(WSForumModel *)modelUse{
    _modelUse = modelUse;
    self.lableUserName.text = modelUse.username;
    NSArray *arr = [modelUse.avatar componentsSeparatedByString:@"/"];
    NSString *url = [NSString stringWithFormat:@"http://%@.fit-time.cn/%@", arr[0], arr[1]];
    [self.imageViewUserPhoto sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"允儿副本.jpg"]];
    // 时间
    NSString *creatTime = [[NSString stringWithFormat:@"%@", modelUse.createTime] substringToIndex:10];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[creatTime doubleValue]];
    NSString *time = [[NSString stringWithFormat:@"%@", confromTimesp] substringWithRange:NSMakeRange(0, 19)];
    NSString *strTime = [NSString stringWithFormat:@"%@月%@日", [time substringWithRange:NSMakeRange(5, 2)], [time substringWithRange:NSMakeRange(8, 2)]];
    
    self.lableTime.text =  strTime;
}



- (void)createSubView {
    
    self.lableTitle = [[UILabel alloc] initWithFrame:CGRectZero];
    self.lableTitle.font = [UIFont systemFontOfSize:17];
    [self.contentView addSubview:self.lableTitle];
    
    self.lableUserName = [[UILabel alloc] initWithFrame:CGRectZero];
    self.lableUserName.font = [UIFont systemFontOfSize:14];
    self.lableUserName.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.lableUserName];
    
    self.lableTime = [[UILabel alloc] initWithFrame:CGRectZero];
    self.lableTime.font = [UIFont systemFontOfSize:14];
    self.lableTime.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.lableTime];
    
    
    self.lableCom = [[UILabel alloc] initWithFrame:CGRectZero];
    self.lableCom.font = [UIFont systemFontOfSize:14];
    self.lableCom.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.lableCom];
    
    self.lableP = [[UILabel alloc] initWithFrame:CGRectZero];
    self.lableP.font = [UIFont systemFontOfSize:14];
    self.lableP.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.lableP];
    
    self.imageViewUserPhoto = [[UIImageView alloc] initWithFrame:CGRectZero];
    self.imageViewUserPhoto.layer.cornerRadius = 20;
    self.imageViewUserPhoto.layer.masksToBounds = YES;
    [self.contentView addSubview:self.imageViewUserPhoto];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.lableTitle.frame = CGRectMake(10, 10, 394, 30);
//    self.imageViewUserPhoto.contentMode = UIViewContentModeScaleAspectFill;
    self.imageViewUserPhoto.frame = CGRectMake(10, 45, 40, 40);
    self.lableUserName.frame = CGRectMake(60, 45, 180, 20);
    self.lableTime.frame = CGRectMake(60, 65, 180, 20);
    self.lableCom.frame = CGRectMake(254, 55, 70, 30);
    self.lableP.frame = CGRectMake(334, 55, 70, 30);
    
}

@end
